import os

from dao.evaluationdao import EvaluationDao
from dao.traindatadao import TrainDataDao


class CleanImg():
    dao = EvaluationDao()

    def clean(self):
        names = []
        name_tuple = self.dao.getAllImgNames()
        for name_tuple1 in name_tuple:
            names.append(name_tuple1[0])
            names.append(name_tuple1[1])
        print(len(names))
        eacc_names_tuple = TrainDataDao().getAllEACCImgName()
        eacc_names_list = []
        for i in eacc_names_tuple:
            eacc_names_list.append(i[0])

        print(eacc_names_list)
        model_img_names_tuple = TrainDataDao().getAllModelImgName()
        model_img_names_list=[]
        for i in model_img_names_tuple:
            model_img_names_list.append(i[0])
        print(model_img_names_list)
        names += list(eacc_names_list)
        names += list(model_img_names_list)
        print(len(names))
        print(names)
        all_name = os.listdir("../storage")
        print(len(all_name))
        count = 0
        # print("storage/1PR9348e5e2de3b4464b16c9eeb55b2aa76.png" in names)
        for name in all_name:
            if name.split('.')[1] == 'png':
                # print(name)
                # print('storage/'+name)
                if ('storage/'+name) not in names:
                    print(name)
                    count+=1
                    os.remove('../storage/'+name)

        print(count)
if __name__ == "__main__":
    CleanImg().clean()
